package notes.java.java8.demo.streams;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**映射*/
public class S3_Map {
	
	public static void main(String[] args) {
		// 测试数据
		List<Person> persons = new ArrayList<>();
		Person p = new Person();
		p.setAge(36);
		p.setSex("男");
		p.setName("zhangsan");
		persons.add(p);
		
		Person p2 = new Person();
		p2.setAge(22);
		p2.setSex("男");
		p2.setName("lisi");
		persons.add(p2);
		
		Person p3 = new Person();
		p3.setAge(25);
		p3.setSex("女");
		p3.setName("lili");
		persons.add(p3);
		
		// 将名称以逗号分割成字符串
		String names = persons.stream().map(Person::getName).collect(Collectors.joining(","));
		
		// 输出
		System.out.println(names);
	}

}

/**
 * @author wangcs
 *
 */
class Person {
	private String name;
	private int age;
	private String sex;
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	public String getSex() {
		return sex;
	}
	public void setSex(String sex) {
		this.sex = sex;
	}
	
}